//
//  LGPatientAttendHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/5/17.
//

#import "LGPatientAttendHeader.h"

@interface LGPatientAttendHeader()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)CAGradientLayer *shadowLayer;
/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
@property (nonatomic , strong)UIButton *tipButton;
/**   */
@property (nonatomic , strong)UIButton *touchButton;

@end

@implementation LGPatientAttendHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)tipButtonAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(openCloseHeaderView:section:)]){
        [self.delegate openCloseHeaderView:!self.opened section:self.section];
    }
}

-(void)setTitle:(NSString *)title{
    _title = title;
    NSString *normal = [NSString stringWithFormat:@"%@Normal",title];
    NSString *selected = [NSString stringWithFormat:@"%@Selected",title];
    [self.titleBtn setTitle:title forState:UIControlStateNormal];
    [self.titleBtn setImage:[UIImage imageNamed:normal] forState:UIControlStateNormal];
    [self.titleBtn setImage:[UIImage imageNamed:selected] forState:UIControlStateSelected];
    if([title isEqualToString:@"居家监测"]){
        self.touchButton.hidden = YES;
        self.tipButton.hidden = YES;
        self.checkBtn.hidden = NO;
    }else{
        self.touchButton.hidden = NO;
        self.tipButton.hidden = NO;
        self.checkBtn.hidden = YES;
    }
}

-(void)setOpened:(BOOL)opened{
    _opened = opened;
    self.shadowLayer.hidden = !opened;
    self.tipButton.selected = opened;
    
}

-(void)setFinished:(BOOL)finished{
    _finished = finished;
    if([self.title isEqualToString:@"居家监测"]){
        self.titleBtn.selected = YES;
        self.touchButton.userInteractionEnabled = NO;
    }else{
        self.titleBtn.selected = finished;
        self.touchButton.userInteractionEnabled = finished;
    }
    
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.baseView];
    [self.baseView.layer addSublayer:self.shadowLayer];
    [self.baseView addSubview:self.titleBtn];
    [self.baseView addSubview:self.tipButton];
    [self.baseView addSubview:self.touchButton];
    [self.baseView addSubview:self.checkBtn];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(16), viewPix(8), Screen_W-viewPix(32), viewPix(70))];
        [_baseView setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.1 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(CAGradientLayer *)shadowLayer{
    if(!_shadowLayer){
        _shadowLayer = [[CAGradientLayer alloc] init];
        _shadowLayer.frame = CGRectMake(0, 0, Screen_W-viewPix(32), viewPix(40));
        _shadowLayer.startPoint = CGPointMake(0.5, 0.13);
        _shadowLayer.endPoint = CGPointMake(0.5, 1);
        _shadowLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#E8F2FE"].CGColor,(__bridge id)[UIColor colorWithString:@"#FFFFFF"].CGColor];
    }
    return _shadowLayer;
}

-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"" titleFont:LGFontWeight(15, UIFontWeightMedium) normalColor:@"#999999" selectColor:@"#1F6CC6"];
        _titleBtn.frame = CGRectMake(viewPix(12), viewPix(6), viewPix(200), viewPix(40));
        _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _titleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        _titleBtn.userInteractionEnabled = NO;
    }
    return _titleBtn;
}

-(UIButton *)tipButton{
    if(!_tipButton){
        _tipButton = [UIButton buttonWithImage:@"grayTipDown" selectImage:@"grayTipUp"];
        _tipButton.frame = CGRectMake(Screen_W-viewPix(32)-viewPix(12)-viewPix(40), viewPix(6), viewPix(40), viewPix(40));
        _tipButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _tipButton.userInteractionEnabled = NO;
    }
    return _tipButton;
}

-(UIButton *)touchButton{
    if(!_touchButton){
        _touchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _touchButton.frame = CGRectMake(viewPix(100), viewPix(10), Screen_W-viewPix(32)-viewPix(100), viewPix(40));
        [_touchButton addTarget:self action:@selector(tipButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _touchButton;
}

-(UIButton *)checkBtn{
    if(!_checkBtn){
        _checkBtn = [UIButton buttonWithTitle:@"去查看" titleFont:LGFontWeight(13, UIFontWeightMedium) textColor:@"#999999" imageName:@"grayTip12"];
        _checkBtn.frame = CGRectMake(Screen_W-viewPix(32)-viewPix(12)-viewPix(60), viewPix(10), viewPix(60), viewPix(40));
        _checkBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_checkBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:5];
        _checkBtn.hidden = YES;
    }
    return _checkBtn;
}

@end
